package com.ovolucky.mapmytrip.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.ovolucky.mapmytrip.app.storage.TripStore;

public class CreateTripActivity extends Activity {

  public static final String TRIP_ID_KEY = "trip_id";
  private TripStore tripStore;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    tripStore = new TripStore(this);
    setContentView(R.layout.activity_create_trip);
    final TextView title = (TextView) findViewById(R.id.tripTitleEditText);
    final TextView summary = (TextView) findViewById(R.id.tripSummaryEditText);
    Button createButton = (Button) findViewById(R.id.createTripButton);
    createButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        long tripId = tripStore.saveTrip(
            title.getText().toString(), summary.getText().toString());
        Intent intent = new Intent(getBaseContext(), MapActivity.class);
        intent.putExtra(TRIP_ID_KEY, tripId);
        startActivity(intent);
      }
    });
  }
}
